package com.example.home.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;

import com.bumptech.glide.Glide;
import com.example.home.bean.BanBen;

import java.util.List;

public class BannerAdapter extends PagerAdapter {

    private List<BanBen.RowsBean> list_banner;
    private List<View> viewList;
    private Context context;
    private String url = "http://124.93.196.45:10001";

    public BannerAdapter(List<BanBen.RowsBean> list_banner, Context context) {
        this.list_banner = list_banner;
        this.context = context;

    }


    @Override
    public int getCount() {
        return list_banner == null ? 0 : list_banner.size();
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view == object;
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        ImageView imageView = new ImageView(context);
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        Glide.with(context).load(url+list_banner.get(position).getAdvImg()).into(imageView);
        container.addView(imageView);
        return imageView;
    }
    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        container.removeView((View)object);
    }

    @Override
    public int getItemPosition(@NonNull Object object) {
        return super.getItemPosition(object);
    }
}
